package com.hliushi.learn.controller;

import com.hliushi.learn.bean.Person;
import com.hliushi.learn.response.JsonResult;
import com.hliushi.learn.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author llhuang10
 */
@RestController
@RequestMapping("/api")
public class DataValidController {


    @Autowired
    private PersonService personService;

    /**
     * @param
     * @return
     */
    @GetMapping("/person/{personId}")
    public JsonResult<Person> getPerson(@PathVariable String personId) {
        Person person = personService.getPerson(personId);
        return new JsonResult<>(person);
    }


    /**
     * @param
     * @return
     */
    @PutMapping("/person")
    public JsonResult<Person> updatePerson(@RequestBody @Valid Person person) {
        Person result = personService.updatePerson(person);
        return new JsonResult<>(result);
    }

    /**
     * @param
     * @return
     */
    @PostMapping("/person")
    public JsonResult<Person> addPerson(@RequestBody @Valid Person person) {
        Person result = personService.addPerson(person);
        return new JsonResult<>(result);
    }
}
